package com.dao;

import com.github.pagehelper.Page;
import com.pojo.CheckGroup;
import com.pojo.Setmeal;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

public interface SetmealDao {
    //<!--新增套餐,业务层次还要新增与检查组的中间表-->
    int addSetmeal(Setmeal setmeal);
     //<!--根据ID新增中间表-->
    int addSetmealAddCheckGroup(@Param("list") Integer[] list,@Param("sid") int id);
     //<!--分页查询套餐数据,以及对应的关联检查组数据-->
    Page<Setmeal> findAllSetmeal(String a);
    @Select("SELECT c.* FROM t_setmeal_checkgroup sc,t_checkgroup c WHERE c.id=sc.checkgroup_id AND sc.setmeal_id=#{id}")
    List<CheckGroup> findcheckGroupBySid(int id);
//<!--//删除指定套餐,需要删除三张表中的数据-->
    int deleteOrder(int id);
    int deleteCroupAndSetmeal(int id);
    int deleteSetmeal(int id);
    //修改检查组,需要先把中间表相关数据干掉,再插入中间表数据
    int updateSetmeal(Setmeal setmeal);
    //根据id查询相对应的图片名字
    @Select("select img from t_setmeal where id=#{id}")
    String findImgById(int id);
    //不分页查询所有数据
    List<Setmeal> findSetmeal();
    //根据id显示相关套餐组的详细信息
    Setmeal findSetmealById(int id);
    /*统计分析套餐预约情况占比*/
    @Select("SELECT s.name name,COUNT(s.name) value FROM t_order o ,t_setmeal s WHERE o.setmeal_id=s.id GROUP BY s.name")
    List<Map<String, Object>> getSetmealReport();
    //前4名热门套餐集合hotSetmeal  name   setmeal_count  proportion占比
    @Select("SELECT s.name name,COUNT(s.name) setmeal_count,COUNT(s.name)/(SELECT SUM(b.cc) alls FROM (SELECT s.name NAME,COUNT(s.name) cc FROM t_order o ,t_setmeal s WHERE o.setmeal_id=s.id GROUP BY s.name LIMIT 4) b" +
            ") proportion FROM t_order o ,t_setmeal s WHERE o.setmeal_id=s.id GROUP BY s.name LIMIT 4")
    List<Map<String, Object>> getHotSetmeamlData();
}
